import { createAsyncThunk, createSlice } from "@reduxjs/toolkit";
import {User,UserResponse} from '@/types/data'
import { http } from "@/utils/http";


type State={
  user:User
}
// type UserResponse={
//   message:string
//   data:User
// }

export const getUser = createAsyncThunk('profile/getuser',async()=>{
  const res=await http.get<UserResponse>('/user')
  return res.data.data
})

const initialState:State={
  user:{} as User
}

const profile = createSlice({
  name:'profile',
  initialState,
  reducers:{},
  extraReducers:builder=>{
    builder.addCase(getUser.fulfilled,(state,action)=>{
      state.user=action.payload
    })
  }
})

export default profile.reducer